import { request } from '@/utils/request'

// 仪表盘统计数据类型定义
export interface DashboardStats {
  totalStudents: number
  totalResumes: number
  totalInterviews: number
  totalJobs: number
  totalCompanies: number
  totalApplications: number
}

export interface StudentEmploymentStats {
  employed: number
  unemployed: number
  furtherStudy: number
  selfEmployed: number
  military: number
}

export interface ResumeStats {
  draft: number
  inProgress: number
  submitted: number
  approved: number
  rejected: number
}

export interface InterviewStats {
  scheduled: number
  completed: number
  passed: number
  failed: number
  cancelled: number
}

export interface JobStats {
  published: number
  draft: number
  closed: number
  expired: number
}

export interface MonthlyTrend {
  month: string
  interviews: number
  completedInterviews: number
  applications: number
  approvedApplications: number
}

export interface UserRoleStats {
  admin: number
  teacher: number
  student: number
  total: number
}

export interface DashboardData {
  overview: DashboardStats
  studentEmployment: StudentEmploymentStats
  resumeStatus: ResumeStats
  interviewStatus: InterviewStats
  jobStatus: JobStats
  monthlyTrends: MonthlyTrend[]
  userRoles: UserRoleStats
  recentActivities: any[]
}

// 仪表盘API
export const dashboardApi = {
  // 获取仪表盘概览数据
  getOverviewStats: () => {
    return request.get<DashboardStats>('/dashboard/overview/')
  },

  // 获取学生就业状态统计
  getStudentEmploymentStats: () => {
    return request.get<StudentEmploymentStats>('/dashboard/students/employment-statistics/')
  },

  // 获取简历状态统计
  getResumeStats: () => {
    return request.get<ResumeStats>('/dashboard/resume-management/statistics/')
  },

  // 获取面试状态统计
  getInterviewStats: () => {
    return request.get<InterviewStats>('/dashboard/interviews/statistics/')
  },

  // 获取岗位状态统计
  getJobStats: () => {
    return request.get<JobStats>('/dashboard/jobs/statistics/')
  },

  // 获取月度趋势数据
  getMonthlyTrends: (params?: { months?: number }) => {
    return request.get<MonthlyTrend[]>('/dashboard/monthly-trends/', params)
  },

  // 获取用户角色统计
  getUserRoleStats: () => {
    return request.get<UserRoleStats>('/dashboard/auth/user-statistics/')
  },

  // 获取最近活动
  getRecentActivities: (params?: { limit?: number }) => {
    return request.get('/dashboard/recent-activities/', params)
  },

  // 获取完整仪表盘数据
  getDashboardData: () => {
    return request.get<DashboardData>('/dashboard/data/')
  },

  // 根据用户角色获取个性化统计
  getPersonalizedStats: () => {
    return request.get('/dashboard/personalized-stats/')
  }
}

// 学生个人仪表盘API
export const studentDashboardApi = {
  // 获取学生个人统计
  getPersonalStats: () => {
    return request.get('/dashboard/students/my-statistics/')
  },

  // 获取简历完成度
  getResumeProgress: () => {
    return request.get('/dashboard/resume-management/my-progress/')
  },

  // 获取面试历史
  getInterviewHistory: () => {
    return request.get('/dashboard/interviews/my-history/')
  },

  // 获取申请状态
  getApplicationStatus: () => {
    return request.get('/dashboard/jobs/my-applications-status/')
  },

  // 获取推荐岗位
  getRecommendedJobs: (params?: { limit?: number }) => {
    return request.get('/dashboard/jobs/recommendations/', params)
  }
}

// 教师仪表盘API
export const teacherDashboardApi = {
  // 获取负责学生统计
  getMyStudentsStats: () => {
    return request.get('/dashboard/students/my-students-statistics/')
  },

  // 获取待审核简历
  getPendingResumes: () => {
    return request.get('/dashboard/resume-management/pending-reviews/')
  },

  // 获取本月面试安排
  getMonthlyInterviews: () => {
    return request.get('/dashboard/interviews/monthly-schedule/')
  },

  // 获取学生就业进展
  getStudentEmploymentProgress: () => {
    return request.get('/dashboard/students/employment-progress/')
  }
}

// 管理员仪表盘API
export const adminDashboardApi = {
  // 获取系统概览
  getSystemOverview: () => {
    return request.get('/dashboard/system-overview/')
  },

  // 获取用户活跃度
  getUserActivity: (params?: { period?: 'day' | 'week' | 'month' }) => {
    return request.get('/dashboard/auth/user-activity/', params)
  },

  // 获取系统性能指标
  getSystemMetrics: () => {
    return request.get('/dashboard/system-metrics/')
  },

  // 获取数据增长趋势
  getGrowthTrends: (params?: { period?: 'week' | 'month' | 'quarter' }) => {
    return request.get('/dashboard/growth-trends/', params)
  }
}

export default dashboardApi
